﻿using System;
using System.Collections.Generic;
using System.Linq;
using Thuoc24h.Common;
using Thuoc24h.ViewModels;
using Utils = CSS.Utils;

namespace Thuoc24h.Home.Pages
{
    public partial class Product : BasePage.BasePages
    {
        public string keyword = "";
        public string categories = "";
        public List<int?> cats = new List<int?>();
        protected void Page_Load(object sender, EventArgs e)
        {
            MedicineCategoriesLtr.Text = BuilMedicineMenu(null);
        }
        private string BuilMedicineMenu(int? parentId)
        {
            var htmlStr = "";
            var list = context.Categories.Where(it => it.CategoryType == 1).OrderBy(it => it.SortOrder).ToList();
            if (list != null)
            {

                htmlStr += "<ul>";
                foreach (var category in list)
                {
                    if (category.ParentId == parentId)
                    {
                        if (cats.Contains(category.Id))
                        {
                            // htmlStr += string.Format("<li><input type=\"checkbox\" id=\"cate{0}\" value=\"{0}\" checked=\"checked\" class=\"css-checkbox\"/><label for=\"cate{0}\" class=\"css-label\">{1}</label>{2}</li>", category.Id, category.Name, BuilMedicineMenu(category.Id));
                            htmlStr += string.Format("<li><a href=\"/{0}\" class=\"current\">{1}</a>{2}</li>",
                                                string.Format("{0}/{1}", "tim-thuoc",
                                                              Utils.BuildUrl(category.UnsignName, category.Id)),
                                                category.Name, BuilMedicineMenu(category.Id));
                        }
                        else
                        {
                            // htmlStr += string.Format("<li><input type=\"checkbox\" id=\"cate{0}\" value=\"{0}\" class=\"css-checkbox\"/><label for=\"cate{0}\" class=\"css-label\">{1}</label>{2}</li>", category.Id, category.Name, BuilMedicineMenu(category.Id));
                            htmlStr += string.Format("<li><a href=\"/{0}\">{1}</a>{2}</li>",
                                                string.Format("{0}/{1}", "tim-thuoc",
                                                              Utils.BuildUrl(category.UnsignName, category.Id)),
                                                category.Name, BuilMedicineMenu(category.Id));
                        }
                    }
                }
                htmlStr += "</ul>";
            }
            return htmlStr;
        }
    }
}